<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<pre id="codeBox"></pre>
		<script>
			const text = `
			package \${packageName!}.handler;
			
			#if(isNotEmpty(propList)) {
			import \${packageName!}.entity.\${entityName!};
			#}
			import lombok.extern.slf4j.Slf4j;
			import org.springblade.isdp.starter.document.annotation.EventReply;
			import org.springblade.isdp.starter.document.annotation.IsdpComponent;
			import org.springblade.isdp.starter.document.annotation.MsgBody;
			import org.springblade.isdp.starter.document.domain.base.IsdpDefaultMqttConfig;
			import org.springblade.isdp.starter.document.domain.base.MetaDataType;
			import org.springblade.isdp.starter.document.interceptor.IsdpMqttPublishInterceptor;
			import org.springblade.isdp.starter.document.support.IsdpMqttPool;
			import org.springblade.isdp.starter.exception.MethodUndefinedException;
			
			import java.nio.charset.StandardCharsets;
			import java.util.Map;
			
			/**
			 * 在返回值为 {@link String} 的方法上<br/>
			 * 标记 一个 {@linkplain EventReply @EventReply} 来完成 {@code EventReply} 发布.
			 * <p>
			 * 必填参数<br/>
			 * {@linkplain EventReply\#topic() EventReply.topic} 订阅主题.<br/>
			 * <p>
			 * 服务器将使用 {@code Spring AOP} 切面处理标记 {@linkplain EventReply @Pub} 的方法.<br/>
			 * 要求: <br/>
			 * 1. 服务器仅处理标记有 {@linkplain IsdpComponent @IsdpComponent} 的类 <br/>
			 * 2. {@linkplain EventReply @EventReply} 标记的方法一定不能为静态方法, 否则{@code Spring AOP} 无法生成代理方法和代理类 <br/>
			 * 3. {@linkplain EventReply @EventReply} 标记的方法需要返回 {@code String} 类型 <br/>
			 * 4. 可以在其他类中调用标记 {@linkplain EventReply @EventReply} 的方法来完成一次 {@code EventReply} 信息的发布, 消息可以在方法内部通过传参自定义 <br/>
			 *
			 * @author Yang
			 * @see IsdpDefaultMqttConfig IsdpDefaultMqttConfig:默认连接配置文件获取
			 * @see IsdpMqttPublishInterceptor IsdpMqttPublishInterceptor :拦截处理 {@linkplain EventReply @EventReply}
			 * @see IsdpMqttPool IsdpMqttPool连接池
			 **/
			@SuppressWarnings("unused")
			@Slf4j
			@IsdpComponent
			public class EventReplyHandler {
			
			#if(isNotEmpty(eventReplyList)) {
			  #for(eventReplyItem in eventReplyList){
			    /**
			     * EventReply[\${eventReplyItem.ident}] 方法
			     *
			     * @param message 事件接收信息(Isdp默认是触发器表达式通过后, 将GlobalProperty的所有信息json化后传入)
			     * @throws Exception 异常
			     */
			    @EventReply(
			            ident = "\${eventReplyItem.ident!}",
			            name = "\${eventReplyItem.name!}",
			            desc = "\${eventReplyItem.desc!}",
			            #if(isNotEmpty(eventReplyItem.trigger)) {
			            trigger = {
			                #for(triggerItem in eventReplyItem.trigger) {
			                    @Trigger(title = "\${triggerItem.title!}", mode = "\${triggerItem.mode!}", description = "\${triggerItem.description!}", expression = "\${triggerItem.expression!}"),
			                #}
			            },
			            #}
			            msgBodyType = "\${eventReplyItem.msgBodyType!}",
			            #if(isNotEmpty(eventReplyItem.msgBody)) {
			            msgBody = {
			                #for(msgBodyItem in eventReplyItem.msgBody) {
			                    @MsgBody(ident = "\${msgBodyItem.ident!}", name = "\${msgBodyItem.name!}", desc = "\${msgBodyItem.desc!}", type = MetaDataType.\${msgBodyItem.type!"OBJECT"}),
			                #}
			            },
			            #}
			            connector = "\${eventReplyItem.connector!}",
			            topic = "\${eventReplyItem.topic!}"
			    )
			    public void \${eventReplyItem.ident!}(final String message) throws Exception {
			        // MqttPool.publish("\${eventReplyItem.connector!"mqtt.default"}", "\${eventReplyItem.connector!"topic/default"}", message.getBytes(StandardCharsets.UTF_8));
			        throw new MethodUndefinedException("未实现事件具体处理方法");
			    }
			  #} // end for eventList
			#} // end if
			}
			`;
			let generateStatue = 'no'; // no ing ok end
			function delaySet(text, index = 0, delayTime = 50) {
			  setTimeout(() => {
			    const diff = 10;
			    // const codeBox = this.$refs.codeBox;
			    if (["ing", "ok"].includes(generateStatue) && index < text.length - diff || generateStatue === "ok") {
			      codeBox.innerHTML += `\n${text[index++]}`;
			      codeBox && codeBox.scrollTo({
			        top: codeBox.scrollHeight,
			        behavior: "smooth", 
			      });
			    } 
			    if (index < text.length) this.delaySet(text, index, delayTime);
					else generateStatue = 'end';
			  }, delayTime);
			}
			generateStatue = 'ing';
			delaySet(text.split('\n'));
			setTimeout(() => {
				generateStatue = 'ok';
			}, 6000);
		</script>
	</body>
</html>